package com.atguigu.flink.chapter5.transform;

import com.atguigu.flink.WaterSensor;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/19 14:56
 */
public class Flink05_Transform_KeyBy_3 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        env
          .fromElements(new WaterSensor("sensor_1", 1000L, 10), new WaterSensor("sensor_2", 2000L, 20), new WaterSensor("sensor_1", 3000L, 30), new WaterSensor("sensor_1", 4000L, 40))
          .keyBy(new KeySelector<WaterSensor, String>() {
              @Override
              public String getKey(WaterSensor value) throws Exception {
                  return value.getId();
              }
          })
          .sum("vc")
          .print();

        env.execute();
    }
}
/*
这些function 都有一个Rich
 */
